home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / basic / ubmalm.zip / twosum.ub < prev    next >
Text File  |  1990-08-22  |  623b  |  15 lines

  1.  1080   *Twosum(P,&A,&B)
  2.  1090   ' Expresses p = a^2 + b^2, for p=1 (mod 4) and prime.
  3.  1095   ' Expects p to be prime - primality is not tested.
  4.  1100   ' Modeled on the Pascal version.  27 April 1990
  5.  1110   local T,Te,G,Sqrtp
  6.  1120   if P@4<>1 then A=0:B=0:return endif
  7.  1125   Sqrtp=isqrt(P):if (res=0) then A=0:B=0:return endif
  8.  1130   T=1:repeat inc T until kro(T,P)=-1
  9.  1140   G=modpow(T,(P-1)\4,P):if P\2<G then G=P-G endif
  10.  1160   A=P@G
  11.  1170   if A=1 then B=G else
  12.  1190   :while Sqrtp<A:Te=G:G=A:A=Te@G wend
  13.  1200   :if A=0 then B=0 else:B=G@A endif endif
  14.  1210   return ' End of subroutine TwoSum
  15.